package com.ciwong.epaper.common.dialogbottom.reread;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.common.dialogbottom.BaseBottomDialog;
import com.ciwong.epaper.modules.evaluate.ui.dialogfragment.adapter.BaseDFrgAdapter;
import com.ciwong.epaper.modules.evaluate.ui.dialogfragment.adapter.CheckReReadDFrgAdapter;
import com.ciwong.epaper.modules.evaluate.ui.dialogfragment.bean.CheckReReadBean;
import com.ciwong.epaper.modules.evaluate.ui.dialogfragment.viewholder.CheckReReadDFrgViewHolder;
import com.ciwong.epaper.util.ViewUtil;
import com.ciwong.epaper.widget.DividerItemDecoration;
import com.ciwong.mobilelib.utils.ToastUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public abstract class BaseReReadBottomDialog extends BaseBottomDialog {
    public TextView tvTitleBottom;
    private RecyclerView rvBottomDialog;
    private ItemCallBack itemCallBack;
    private CheckReReadDFrgAdapter checkReReadDFrgAdapter;
    public List<CheckReReadBean> mList = new ArrayList<>();
    public static Map<Integer, CheckReReadBean> mHashMap = new HashMap<>();


    public interface ItemCallBack {

        void onItemCallBack(CheckReReadBean bean, int position);
    }

    public void setOnItemCallBackListener(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public void setData(List<CheckReReadBean> mList) {
        this.mList = mList;
        System.out.println("lzh===>mList:"+mList.size()+mList.toString());
        if (checkReReadDFrgAdapter != null)
            checkReReadDFrgAdapter.setData(mList);
    }

    public BaseReReadBottomDialog(Context context, int style) {
        super(context, style);
    }

    @Override
    public void initView(Context context) {
        initViewClick();
        initRecycle(context);
    }

    public void initViewClick() {
        View mRootView = LayoutInflater.from(this.getContext()).inflate(R.layout.dialog_bottom, null);
        mRootView.findViewById(R.id.tl_close).setOnClickListener(this);
        tvTitleBottom = mRootView.findViewById(R.id.tv_title_bottom);
        rvBottomDialog = mRootView.findViewById(R.id.rv_bottom_dialog);
        setContentView(mRootView);
    }

    public void initRecycle(Context context) {
        if (checkReReadDFrgAdapter == null)
            checkReReadDFrgAdapter = new CheckReReadDFrgAdapter(context);
        if (rvBottomDialog == null) return;
        rvBottomDialog.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        rvBottomDialog.setAdapter(checkReReadDFrgAdapter);
        rvBottomDialog.addItemDecoration(new DividerItemDecoration(context, LinearLayoutManager.VERTICAL, ViewUtil.dip2px(context, (float) 0.5), R.color.def_line_color));

        checkReReadDFrgAdapter.setCheckItemListener(new BaseDFrgAdapter.ICheckItemListener<CheckReReadDFrgViewHolder, CheckReReadBean>() {
            @Override
            public void checkItem(CheckReReadDFrgViewHolder holder, CheckReReadBean bean, int position) {
                dismiss();
                if (itemCallBack != null)
                    itemCallBack.onItemCallBack(bean, position);
            }
        });
        checkReReadDFrgAdapter.setData(mList);

    }


}
